package com.community.web.master.controller;


import com.community.common.result.Result;
import com.community.web.master.domain.dto.PageOrdersDto;
import com.community.web.master.domain.vo.OrderWithDetailVo;
import com.community.web.master.domain.vo.PageResult;
import com.community.web.master.service.IOrderDetailService;
import com.community.web.master.service.IOrdersService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 李晶
 * @since 2024-07-02
 */
@RestController
@RequestMapping("/master/orders")
@Api(tags = "订单接口")
@Slf4j
public class OrdersController {

    @Autowired
    IOrdersService iordersService;
    @GetMapping("/pageQuery")
    @ApiOperation("订单分页查询")
    public Result<PageResult> pageQuery(PageOrdersDto pageOrdersDto){
        log.info("订单分页查询"+pageOrdersDto);
        PageResult result= iordersService.pageQuery(pageOrdersDto);
        return Result.success(result);
    }

    @GetMapping("/detail/{orderNo}")
    @ApiOperation("根据订单号查看订单详情")
    public Result<List<OrderWithDetailVo>> getOrderDetailByOrderNo(@PathVariable String orderNo){
        log.info("根据id号查看订单详情"+orderNo);
        List<OrderWithDetailVo> result =iordersService.getOrderDetailByOrderNo(orderNo);
        return Result.success(result);
    }

    @PutMapping("/deliveryBatch")
    @ApiOperation("批量发货")
    public Result deliveryBatch(@RequestBody List<Integer> ids){
        log.info("批量发货"+ids);
        iordersService.deliveryBatch(ids);
        return Result.success();
    }
}
